/*
 * 
 * Created on Jul 22, 2005
 */
package com.wgo.precise.client.ui.view.editor.usertypes;

import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;

import com.wgo.precise.client.ui.model.ClientModelItem;


/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: PropertySpecificationTransfer.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 * 
 *
 */
public class PropertySpecificationTransfer extends Transfer {

    enum SupportedTransferType {
        PROJECT("rmt-project-transfer"){}
        ,
        CATEGORY_TYPE("rmt-categoryType-transfer"){}
        ,
        CATEGORY("rmt-category-transfer"){}
        ,
        REQUIREMENT("rmt-requirement-transfer"){}
        ,
        STAKEHOLDER("rmt-stakeholder-transfer"){}
        ;
        private int ID;
        private String TYPE_NAME;

        private SupportedTransferType(String type) {
            this.TYPE_NAME = type;
            ID = registerType(TYPE_NAME);
        }
        int getID() {
            return ID;
        }
        String getTYPE_NAME() {
            return TYPE_NAME;
        }
        protected static String[] getTypeNames() {
            int enums = values().length;
            String[] typeNames = new String[enums];
            for(int i = 0; i < enums; i++){
                typeNames[i] = values()[i].getTYPE_NAME();
            }
            return typeNames;
        }
        protected static int[] getTypeIds() {
            int enums = values().length;
            int[] idValues = new int[enums];
            for(int i = 0; i < enums; i++){
                idValues[i] = values()[i].getID();
            }
            return idValues;
        }
    }

    private static PropertySpecificationTransfer instance;

    private PropertySpecificationTransfer() {
    }

    public static PropertySpecificationTransfer getInstance() {
        if (instance == null) {
            instance = new PropertySpecificationTransfer();
        }
        return instance;
    }
    /**
     * @see org.eclipse.swt.dnd.Transfer#getSupportedTypes()
     */
    @Override
    public TransferData[] getSupportedTypes() {
        int size = SupportedTransferType.values().length;
        TransferData[] data = new TransferData[size];
        for (int i = 0; i < size; i++) {
            data[i] = new TransferData();
            data[i].type = SupportedTransferType.values()[i].getID();
        }
        return data;
    }

    /**
     * @see org.eclipse.swt.dnd.Transfer#isSupportedType(org.eclipse.swt.dnd.TransferData)
     */
    @Override
    public boolean isSupportedType(TransferData transferData) {
        if (transferData == null) {
            return false;
        }
        int[] types = getTypeIds();
        for (int i = 0; i < types.length; i++) {
            if (transferData.type == types[i]) { 
                return true;
            }
        }
        return false;
    }

    /**
     * @see org.eclipse.swt.dnd.Transfer#getTypeNames()
     */
    @Override
    protected String[] getTypeNames() {
        return SupportedTransferType.getTypeNames();
    }

    /**
     * @see org.eclipse.swt.dnd.Transfer#getTypeIds()
     */
    @Override
    protected int[] getTypeIds() {
        return SupportedTransferType.getTypeIds();
    }

    /* (non-Javadoc)
     * @see org.eclipse.swt.dnd.Transfer#javaToNative(java.lang.Object, org.eclipse.swt.dnd.TransferData)
     */
    @Override
    protected void javaToNative(@SuppressWarnings("unused") Object object, @SuppressWarnings("unused") TransferData transferData) {
        // TODO Auto-generated method stub
        
    }

    /* (non-Javadoc)
     * @see org.eclipse.swt.dnd.Transfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
     */
    @Override
    protected Object nativeToJava(@SuppressWarnings("unused") TransferData transferData) {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * @see org.eclipse.swt.dnd.Transfer#validate(java.lang.Object)
     */
    @Override
    protected boolean validate(Object object) {
        return object instanceof ClientModelItem;
    }

}
/**
 * Changelog:
 * 
 * $Log: PropertySpecificationTransfer.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2005-12-03 14:38:48  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/11/16 16:43:28  petterei
 * mye testing...
 *
 * Revision 1.2  2005/09/27 17:06:19  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/08/28 18:01:26  peide3
 * save in Eclipse-way
 * dynamic propertyspecifications bug fixed
 * dnd to deside order of property specification
 * ItemType to make convertion more understandable
 *
 * 
 */